package cn.org.dian.easycommunicate;

import cn.org.dian.easycommunicate.util.Utilities;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.TabHost;

public class MainFrame extends TabActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS,
                R.layout.progress);
        setContentView(R.layout.main_frame);

        createTabs();
    }

    private void createTabs() {
        TabHost tabHost = getTabHost();

        tabHost.addTab(tabHost
                .newTabSpec("local")
                .setIndicator(getString(R.string.local_indicator),
                        getResources().getDrawable(R.drawable.local_tag_small))
                .setContent(new Intent(this, LocalContentActivity.class)));

        tabHost.addTab(tabHost
                .newTabSpec("online")
                .setIndicator(getString(R.string.online_indicator),
                        getResources().getDrawable(R.drawable.online_tag_small))
                .setContent(new Intent(this, OnlineTranslateActivity.class)));
        
        getTabHost().setCurrentTab(0);
    }

    @Override
    public void onBackPressed() {

        AlertDialog alertDialog = new AlertDialog.Builder(this)
                .setMessage(R.string.exit_prompt)
                .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        WelcomeActivity.isExiting = true;
                        MainFrame.this.finish();
                    }
                })
                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                }).create();

        alertDialog.show();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return Utilities.onCreateOptionsMenu(this, menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return Utilities.onOptionsItemSelected(this, item);
    }


}
